<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>分享一张免费腾讯视频月卡给你</title>
    <link rel="stylesheet" href="__JS__/layui/css/layui.css">
    <style>
        html {
            overflow: hidden
        }

        body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td {
            margin: 0;
            padding: 0;
            color: #444444;
            font: 14px/1.5 Microsoft YaHei, Helvitica, Verdana, Arial, san-serif;
        }

        body {
            background-color: #7e65ab;
        }

        #outer-cont {
            position: relative;
            margin: .5rem auto 0;
            width: 85%;
        }

        #inner-cont {
            position: absolute;
            width: 100%;
            top: 7rem;
        }

        #outer {
            margin: 0 auto;
        }

        #outer img {
            display: block;
            margin: 0 auto;

        }

        #inner img {
            display: block;
            margin: 0 auto;
            width: 4rem;
            cursor: pointer;
        }

        .main img {
            max-width: 100%;
            border: 0 none;
        }

        .boxcontent {
            margin: 15px 15px 0;
            border-radius: 5px;
            padding: 2px;
            background-color: #FEF8B2;
            -webkit-box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
            -moz-box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
            -o-box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
            box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);

            margin-bottom: 15px;
        }

        .boxwhite {
            background-color: #ffffff;
        }

        .box {
            border-radius: 5px;
            font-size: 14px;
            border: 1px dashed rgba(0, 0, 0, 0.3);
        }

        .box .title-red {
            padding: 0 5px 0 10px;
            background: url(__H5__/title-bg-red.png) no-repeat 0 0;
            border-radius: 3px 3px 3px 0;
            color: #ffffff;
            height: 22px;
            margin: -1px;
        }

        .box .Detail {
            padding: 15px;
        }

        .Detail img {
            height: auto;
            max-width: 100%;
            border: 0 none;
        }

        input::-moz-placeholder, textarea::-moz-placeholder {
            color: #999;
        }

        #outer {
            margin: 0 5px;
        }

        .qr {
            text-align: center;
        }

        .qr img {
            margin-bottom: .5em;
            box-shadow: #555 0 0 3px;
            width: 50%;
            height:50%;
        }

        .pre {
            position: absolute;
            width: 10%;
            top: 1rem;
            right: 1rem;
            z-index:99999;
        }


    </style>
</head>
<body>
<div class="main">
    <div class="pre">
        <!--<button class="copyBtn" data-clipboard-target="#copy">复制暗号</button>-->
        <img id="pre" src="__H5__/pre_icon.png?1">
    </div>
    <div id="outercont">
        <div id="outer-cont">
            <div id="outer">
                <img src="__H5__/zp8-.png?4">
            </div>
        </div>
        <div id="inner-cont">
            <div id="inner"><img src="__H5__/activity-lottery-2.png"></div>
        </div>
        <div class="boxcontent boxwhite">
            <div class="box">
                <div class="title-red">活动说明：</div>
                <div class="Detail">
                    <p>1、关注CBOX精选公众号可参与抽奖</p>
                    <p>2、用户每天可获得一次抽奖机会，抽完为止</p>
                    <p>3、中奖用户凭获得的暗号”添加盒姐（微信号cute200165）为好友，对接暗号后获得奖励。每个暗号仅可核对一次</p>
                    <p>4、本次活动最终解释权归CBOX所有</p>
                </div>
                <div class="qr" style="">
                    <img src="__H5__/qr1.png" alt="">
                </div>
            </div>
        </div>
    </div>
</div>
<input type="text" id="copy" readonly value="111" style="display: none"/>
<script src="__JS__/jquery.min.js"></script>
<script src="__JS__/layui/layui.all.js"></script>
<!--<script src="https://cdn.bootcss.com/clipboard.js/2.0.4/clipboard.min.js"></script>-->
<!--<script src="https://cdn.bootcss.com/vConsole/3.3.2/vconsole.min.js"></script>-->
<script>
    //    var vConsole = new VConsole();
    var totalDeg = 360 * 6;
    var prizeDeg = [60, 180, 300];
    var lostDeg = [0];
    var steps = [];
    var index = 0;
    var running = false;
    var rid, rname;

    //获取历史中奖信息
    $("#pre").click(function () {
        $.ajax({
            url: '/turnplate_get',
            type: "POST",
            dataType: "json",
            data: {},
            success: function (res) {
                if(res.code == 200){
                    layer.open({
                        title: '提示',
                        area: ['60%', '10rem'],
                        content: '您已中奖，暗号：' + res.msg + '，请长按复制或截图保存暗号，进行兑奖!'
                    });
                } else {
                    layer.open({
                        title: '提示',
                        area: ['60%', '10rem'],
                        content: res.msg
                    });
                }
            }
        });
    });

    //点击抽奖
    $("#inner").click(function () {
        if (running) {
            return;
        }

        $.ajax({
            url: '/turnplate',
            type: "POST",
            dataType: "json",
            data: {},
            success: function (res) {
                if(res.code == 200){
                    rid = res.data.rid;
                    rname = res.data.rname;
                    if (rid == 0) {
                        start();
                    } else {
                        start(prizeDeg[rid - 1]);
                    }
                } else {
                    layer.open({
                        title: '提示',
                        area: ['60%', '10rem'],
                        content: res.msg
                    });
                }
            }
        });
    });

    //开始转盘
    function start(deg) {
        deg = deg || lostDeg[parseInt(lostDeg.length * Math.random())];
        running = true;
        totalDeg += deg;
        steps = [];
        index = 0;
        countSteps();
        requestAnimFrame(step);
    }

    //转盘完成后的提示
    function webTip() {
        if (rid == 0) {
            layer.open({
                title: '提示',
                area: ['60%', '10rem'],
                content: rname
            });
        } else {
            layer.open({
                title: '提示',
                area: ['60%', '10rem'],
                content: '您已中奖，暗号：' + rname + '，请长按复制或截图保存暗号，进行兑奖!'
            });
        }
    }

    //计算每步转盘角度
    function countSteps() {
        var a = 0.01;
        var t = Math.sqrt(2 * totalDeg / a);
        var v = a * t;
        for (var i = 0; i < t; i++) {
            steps.push((2 * v * i - a * i * i) / 2)
        }
        steps.push(totalDeg)
    }

    //转盘动画
    function step() {
        var outer = document.getElementById('outer');
        outer.style.webkitTransform = 'rotate(' + steps[index++] + 'deg)';
        outer.style.MozTransform = 'rotate(' + steps[index++] + 'deg)';
        if (index < steps.length) {
            running = true;
            requestAnimFrame(step)
        } else {
            running = false;
            webTip();
        }
    }

    //动画渲染函数
    window.requestAnimFrame = (function () {
        return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
            function (callback) {
                window.setTimeout(callback, 3000)
            }
    })();
</script>
<script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?7741d4cbd941d985eb296c908ef40bf2";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
</body>
</html>